package com.chris.homecare.components.renderers
{
	import com.chris.homecare.utils.CommonUtils;
	
	import feathers.controls.Label;
	import feathers.controls.renderers.LayoutGroupGroupedListHeaderOrFooterRenderer;
	
	import starling.display.DisplayObject;
	import starling.display.Quad;
	
	public class EmployeesListHeaderRenderer extends LayoutGroupGroupedListHeaderOrFooterRenderer
	{
		protected var headLabel:Label;
		protected var background:Quad;
		private var bottomBorder:DisplayObject;
		
		public function EmployeesListHeaderRenderer()
		{
			super();
		}
		
		override protected function initialize():void
		{
			this.height = 55*CommonUtils.scaleValue;
			
			this.background = new Quad(10,10,0x5b8bc4);
			addChild(this.background);
			
			bottomBorder = new Quad(10, 1, 0xe6e6e6);
			addChild(this.bottomBorder);
			
			this.headLabel = new Label();
			this.headLabel.nameList.add("grouplist-head-label");
			addChild(headLabel);
		}
		
		override protected function draw():void{
			super.draw();
			autoSizeIfNeeded();
		}
		
		protected function autoSizeIfNeeded():Boolean
		{
			const needsWidth:Boolean = isNaN(this.explicitWidth);
			const needsHeight:Boolean = isNaN(this.explicitHeight);

			bottomBorder.y = this.height - 1;
			bottomBorder.width = this.width;
			
			if(!needsWidth && !needsHeight)
			{
				return false;
			}
			
			this.width = this.explicitWidth;
			this.height = this.explicitHeight;
			
			this.validate();
			
			var newWidth:Number = this.explicitWidth;
			if(needsWidth)
			{
				newWidth = this.width;
			}
			var newHeight:Number = this.explicitHeight;
			if(needsHeight)
			{
				newHeight = this.height;
			}
			
			return this.setSizeInternal(newWidth, newHeight, false);
		}
		override protected function commitData():void
		{
			if(this._data && this._owner)
			{
				headLabel.text=this._data.toString();
				
				headLabel.y = 8;
				headLabel.x = 10;
				this.background.width = this.width;
				this.background.height = this.height;
			}
			else
			{
				this.headLabel.text = null;
			}
		}
	}
}